<?php
namespace Api;
use Kuyuan\WqCore\api\Api;
use Kuyuan\WqCore\util\Util;

/**
 * 分享相关
 * Class Share
 * @package Api
 */
class Share extends Api
{
    private $Share = null;
    public function __construct()
    {
        parent::__construct();
        $this->Share = new \Controller\Share();
    }

    /**
     * 通过一个分享id返回分享相关信息
     */
    public function find()
    {
        Util::appointPost();
        $_data = $this->Share->find($this->_gpc["share_id"]);
        if($_data) {
            $_result = array("code"=>0,"data"=>$_data);
        } else {
            $_result = array("code"=>100);
        }
        Util::returns($_result);
    }

    /**
     * 分享红包参数
     */
    public function share()
    {
        Util::appointGet();
        $Red = $this->newController("Red");
        $_share = $Red->findShareParam($this->_gpc["red_id"]);
        if($_share) {
           $Share = $this->newController("Share");
           $_share = array(
                'title'=>$_share['title'],
                'desc'=>$_share['owner_nickname'].'的红包',
                'link'=>murl('entry//mobile',array('m'=>'kuyuan_hb','share_id'=>$Share->add($this->_gpc["red_id"])),true,true),
                'imgUrl'=>$_share['cover'] ? $_share['cover'] : MODULE_URL."media/images/share-cover.jpg"
            );
            $_result = array("code"=>0,"data"=>$_share);
        } else {
            $_result = array("code"=>100);
        }
        Util::returns($_result);
    }
}